var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Component({
    properties: {
        DataInfo: {
            type: null
        },
        store: {
            type: null
        },
        store_id: {
            type: null
        },
        goods_id: {
            type: Number
        },
        isType: {
            type: null
        }
    },
    data: {
        uploadUrl: "",
        store_id: "",
        sectionOptions: [],
        objectMultiArray: [],
        multiIndex: [ 0, 0, 0 ],
        regional: "请选择商品分类",
        cargon_data: {
            title: "",
            sku: "",
            thumb: "",
            price: "",
            market_price: "",
            cost_price: "",
            stock: "",
            thumb_url: "",
            goods_sn: "",
            product_sn: ""
        },
        imageUrl: "",
        fileList2: [],
        fileList1: [],
        upNumMax: 0,
        upNumMaxOther: 0,
        fileList3: [],
        fileList4: [],
        selectedOptions3: [],
        jumpState: !0,
        shopText: ""
    },
    lifetimes: {
        attached: function() {},
        moved: function() {},
        detached: function() {},
        ready: function() {
            console.log(this.properties.store), this.properties.store && this.setData({
                store: this.data.store
            }), this.properties.store_id && (this.setData({
                store_id: this.data.store_id
            }), this._getJson()), this.properties.goods_id && (this.setData({
                goods_id: this.properties.goods_id
            }), this._getJson(!0)), this._urlUp();
        }
    },
    attached: function() {},
    ready: function() {},
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        areaInp: function(t) {
            console.log(t);
            var a = t.detail.value;
            this.setData({
                shopText: a
            });
        },
        _urlUp: function() {
            ("store" == this.data.store || "supplier" == this.data.store) && this.setData({
                uploadUrl: "upload.uploadPic"
            });
        },
        _getJson: function() {
            var t = arguments.length > 0 && void 0 !== arguments[0] && arguments[0], e = this;
            if ("store" == e.data.store) {
                var i = a.getNetAddresss("plugin.store-cashier.frontend.store.goods-category.get-category-by-store-id");
                i += "&store_id=" + e.properties.store_id, a._getNetWork({
                    url: i,
                    success: function(a) {
                        var i = a.data, s = [];
                        if (console.log(i, "ssssssss"), i.data.length > 0 && i.data.list.map(function(t) {
                            s.push({
                                name: t.name,
                                id: t.id,
                                childrens: t.childrens
                            });
                        }), e.setData({
                            list: s
                        }), 1 == i.result) {
                            for (var d = [], n = 0; n < i.data.list.length; n++) {
                                d.push({
                                    id: i.data.list[n].id,
                                    name: i.data.list[n].name,
                                    children: []
                                });
                                for (var r = 0; r < i.data.list[n].childrens.length; r++) d[n].children.push({
                                    id: i.data.list[n].childrens[r].id,
                                    name: i.data.list[n].childrens[r].name
                                });
                            }
                            e.setData({
                                sectionOptions: d
                            }), console.log(d), e.goodsHandlefunction(), t && e.getGoodsJson();
                        } else wx.showToast({
                            icon: "none",
                            title: i.msg,
                            duration: 1500
                        });
                    },
                    fail: function(t) {
                        console.log(t.msg);
                    }
                });
            } else if ("supplier" == e.data.store) {
                var s = a.getNetAddresss("plugin.supplier.frontend.goods.get-category");
                a._postNetWork({
                    url: s,
                    showToastIn: !1,
                    data: {},
                    success: function(a) {
                        var i = a.data, s = [];
                        if (i.data.map(function(t) {
                            s.push({
                                name: t.name,
                                id: t.id,
                                childrens: t.childrens
                            });
                        }), e.setData({
                            list: s
                        }), 1 == i.result) {
                            for (var d = [], n = 0; n < i.data.length; n++) if (d.push({
                                id: i.data[n].id,
                                name: i.data[n].name,
                                children: []
                            }), !i.data[n].childrens || i.data[n].childrens.length < 1) ; else for (var r = 0; r < i.data[n].childrens.length; r++) if (d[n].children.push({
                                id: i.data[n].childrens[r].id,
                                name: i.data[n].childrens[r].name,
                                children: []
                            }), !i.data[n].childrens[r].childrens || i.data[n].childrens[r].childrens.length < 1) ; else for (var o = 0; o < i.data[n].childrens[r].childrens.length; o++) d[n].children[r].children.push({
                                id: i.data[n].childrens[r].childrens[o].id,
                                name: i.data[n].childrens[r].childrens[o].name
                            });
                            e.setData({
                                sectionOptions: d
                            }), e.goodsHandlefunction(), t && e.getGoodsJson();
                        } else wx.showToast({
                            icon: "none",
                            title: i.msg,
                            duration: 1500
                        });
                    },
                    fail: function(t) {}
                });
            }
        },
        commodityBtn: function(a) {
            var e = a.detail.column, i = a.detail.value, s = {
                multiArray: this.data.objectMultiArray
            };
            switch (this.setData(t({}, "multiIndex[" + e + "]", i)), e) {
              case 0:
                this.selecommodity_0(i);
                break;

              case 1:
                this.selecommodity_1(this.data.multiIndex[0], i);
            }
            this.setData(s);
        },
        goodsHandlefunction: function() {
            for (var t = this.data.sectionOptions, a = [], e = [], i = [], s = 0; s < t.length; s++) a.push({
                id: t[s].id,
                name: t[s].name
            });
            if (t[0].children.length > 0) for (var d = 0; d < t[0].children.length; d++) e.push({
                id: t[0].children[d].id,
                name: t[0].children[d].name
            });
            if (t[0].children && t[0].children.length > 0 && t[0].children[0].children && t[0].children[0].children.length > 0) for (var n = 0; n < t[0].children[0].children.length; n++) i.push({
                id: t[0].children[0].children[n].id,
                name: t[0].children[0].children[n].name
            });
            this.setData({
                "objectMultiArray[0]": a,
                "objectMultiArray[1]": e,
                "objectMultiArray[2]": i
            }), console.log(this.data.objectMultiArray);
        },
        selecommodity_0: function(t) {
            var a = this.data.sectionOptions, e = [], i = [];
            if (a[t].children.length > 0) for (var s = 0; s < a[t].children.length; s++) e.push({
                id: a[t].children[s].id,
                name: a[t].children[s].name
            });
            if (a[t].children && a[t].children.length > 0 && a[t].children[0].children && a[t].children[0].children.length > 0) for (var d = 0; d < a[t].children[0].children.length; d++) i.push({
                id: a[t].children[0].children[d].id,
                name: a[t].children[0].children[d].name
            });
            this.setData({
                "objectMultiArray[1]": e,
                "objectMultiArray[2]": i,
                "multiIndex[1]": 0,
                "multiIndex[2]": 0
            });
        },
        selecommodity_1: function(t, a) {
            var e = this.data.sectionOptions, i = [];
            if (e[t].children && e[t].children.length > 0 && e[t].children[a].children && e[t].children[a].children.length > 0) for (var s = 0; s < e[t].children[a].children.length; s++) i.push({
                id: e[t].children[a].children[s].id,
                name: e[t].children[a].children[s].name
            });
            this.setData({
                "objectMultiArray[2]": i,
                "multiIndex[2]": 0
            });
        },
        commodityconfirm: function(t) {
            var a = t.detail.value[0];
            if (this.data.list[a] && 0 == this.data.list[a].childrens.length) wx.showToast({
                title: "至少要选择二级分类",
                icon: "none",
                duration: 2e3
            }); else {
                var e = this.data.sectionOptions, i = t.detail.value, s = i[0], d = i[1], n = i[2], r = [], o = [];
                e.length > 0 && (r.push(e[s].id), o.push(e[s].name), e[s].children.length > 0 && (r.push(e[s].children[d].id), 
                o.push(e[s].children[d].name), e[s].children[d].children && e[s].children[d].children.length > 0 && (r.push(e[s].children[d].children[n].id), 
                o.push(e[s].children[d].children[n].name)))), this.setData({
                    regional: o.join("/"),
                    selectedOptions3: r
                });
            }
        },
        onRead: function() {
            var t = this, e = a.getNetAddresss(this.data.uploadUrl);
            wx.chooseImage({
                count: 1,
                sizeType: [ "original", "compressed" ],
                sourceType: [ "album", "camera" ],
                success: function(a) {
                    var i = a.tempFilePaths;
                    wx.compressImage({
                        src: i[0],
                        quality: 60,
                        success: function(a) {
                            var i = a.tempFilePath;
                            wx.uploadFile({
                                url: e,
                                filePath: i,
                                name: "file",
                                success: function(a) {
                                    var e = JSON.parse(a.data);
                                    1 == e.result ? t.setData({
                                        imageUrl: i,
                                        "cargon_data.thumb": e.data.img
                                    }) : wx.showToast({
                                        icon: "none",
                                        title: e.msg,
                                        duration: 1500
                                    });
                                }
                            });
                        },
                        fail: function(t) {},
                        complete: function(t) {}
                    });
                }
            });
        },
        onRead_1: function() {
            var t = this, e = a.getNetAddresss(this.data.uploadUrl);
            wx.chooseImage({
                count: 1,
                sizeType: [ "original", "compressed" ],
                sourceType: [ "album", "camera" ],
                success: function(a) {
                    var i = a.tempFilePaths;
                    wx.compressImage({
                        src: i[0],
                        quality: 60,
                        success: function(a) {
                            var i = a.tempFilePath;
                            wx.uploadFile({
                                url: e,
                                filePath: i,
                                name: "file",
                                formData: {
                                    attach: "upload"
                                },
                                success: function(a) {
                                    var e = JSON.parse(a.data);
                                    if (1 == e.result) {
                                        var s = t.data.fileList1, d = t.data.fileList2;
                                        s.push({
                                            url: e.data.img
                                        }), d.push({
                                            url: i
                                        }), t.setData({
                                            upNumMax: t.data.upNumMax + 1,
                                            fileList1: s,
                                            fileList2: d
                                        });
                                    } else wx.showToast({
                                        icon: "none",
                                        title: e.msg,
                                        duration: 1500
                                    });
                                }
                            });
                        },
                        fail: function(t) {},
                        complete: function(t) {}
                    });
                }
            });
        },
        removeImg: function(t) {
            var a = t.currentTarget.dataset.index, e = this.data.fileList1, i = this.data.fileList2;
            e.splice(a, 1), i.splice(a, 1), this.setData({
                fileList1: e,
                fileList2: i
            }), this.setData({
                upNumMax: this.data.fileList1.length
            });
        },
        onRead_2: function() {
            var t = this, e = a.getNetAddresss(this.data.uploadUrl);
            wx.chooseImage({
                count: 1,
                sizeType: [ "original", "compressed" ],
                sourceType: [ "album", "camera" ],
                success: function(a) {
                    var i = a.tempFilePaths;
                    wx.compressImage({
                        src: i[0],
                        quality: 60,
                        success: function(a) {
                            var i = a.tempFilePath;
                            wx.uploadFile({
                                url: e,
                                filePath: i,
                                name: "file",
                                formData: {
                                    attach: "upload"
                                },
                                success: function(a) {
                                    var e = JSON.parse(a.data);
                                    if (1 == e.result) {
                                        var s = t.data.fileList3, d = t.data.fileList4;
                                        s.push({
                                            url: e.data.img_url
                                        }), d.push({
                                            url: i
                                        }), t.setData({
                                            upNumMaxOther: t.data.upNumMaxOther + 1,
                                            fileList3: s,
                                            fileList4: d
                                        });
                                    } else wx.showToast({
                                        icon: "none",
                                        title: e.msg,
                                        duration: 1500
                                    });
                                }
                            });
                        },
                        fail: function(t) {},
                        complete: function(t) {}
                    });
                }
            });
        },
        removeImg_1: function(t) {
            var a = t.currentTarget.dataset.index, e = this.data.fileList3, i = this.data.infoArr;
            e.splice(a, 1), this.setData({
                fileList3: e,
                infoArr: i
            }), this.setData({
                upNumMaxOther: this.data.fileList3.length
            });
        },
        titleinp: function(t) {
            var a = t.detail.value;
            this.setData({
                "cargon_data.title": a
            });
        },
        skuinp: function(t) {
            var a = t.detail.value;
            this.setData({
                "cargon_data.sku": a
            });
        },
        priceinp: function(t) {
            var a = t.detail.value;
            if (-1 !== a.indexOf(".")) {
                var e = a.indexOf("."), i = (a = a.replace(/[^\d]/g, "")).slice(0, e) + "." + a.slice(e);
                this.setData({
                    "cargon_data.price": i
                });
            } else this.setData({
                "cargon_data.price": a
            });
        },
        marketpriceinp: function(t) {
            var a = t.detail.value;
            if (-1 !== a.indexOf(".")) {
                var e = a.indexOf("."), i = (a = a.replace(/[^\d]/g, "")).slice(0, e) + "." + a.slice(e);
                this.setData({
                    "cargon_data.market_price": i
                });
            } else this.setData({
                "cargon_data.market_price": a
            });
        },
        costPriceinp: function(t) {
            var a = t.detail.value;
            if (-1 !== a.indexOf(".")) {
                var e = a.indexOf("."), i = (a = a.replace(/[^\d]/g, "")).slice(0, e) + "." + a.slice(e);
                this.setData({
                    "cargon_data.cost_price": i
                });
            } else this.setData({
                "cargon_data.cost_price": a
            });
        },
        stockinp: function(t) {
            var a = t.detail.value;
            this.setData({
                "cargon_data.stock": a
            });
        },
        inpTap: function(a) {
            var e = a.currentTarget.dataset.key;
            this.setData(t({}, "cargon_data.".concat(e), a.detail.value));
        },
        setJson: function() {
            var t = [];
            if (0 != this.data.fileList1.length) for (var e = 0; e < this.data.fileList1.length; e++) t.push(this.data.fileList1[e].url); else t = [];
            var i = [];
            if (0 != this.data.fileList3.length) for (var s = 0; s < this.data.fileList3.length; s++) i.push(this.data.fileList3[s].url); else i = [];
            var d = {};
            if (!this.data.isType) {
                a._isTextEmpty(this.data.infoArr) && this.setData({
                    infoArr: []
                }), console.log(this.data.infoArr, this.data.fileList3, "两个链接的数组");
                var n = this.data.infoArr.concat(this.data.fileList3);
                if (i = [], 0 != n.length) for (var r = 0; r < n.length; r++) "-1" == n[r].url.indexOf("wxfile") && i.push(n[r].url); else i = [];
            }
            "store" == this.data.store ? (d = {
                store_id: this.data.store_id,
                category_pid: this.data.selectedOptions3[0],
                category_cid: this.data.selectedOptions3[1],
                title: this.data.cargon_data.title,
                thumb: this.data.cargon_data.thumb,
                thumb_url: i,
                good_content: t,
                cost_price: this.data.cargon_data.cost_price,
                market_price: this.data.cargon_data.market_price,
                price: this.data.cargon_data.price,
                sku: this.data.cargon_data.sku,
                stock: this.data.cargon_data.stock,
                goods_sn: this.data.cargon_data.goods_sn,
                product_sn: this.data.cargon_data.product_sn
            }, this.data.isType || (d = {
                store_id: this.data.store_id,
                goods_id: this.data.goods_id,
                category_pid: this.data.selectedOptions3[0],
                category_cid: this.data.selectedOptions3[1],
                title: this.data.cargon_data.title,
                thumb: this.data.cargon_data.thumb,
                thumb_url: i,
                cost_price: this.data.cargon_data.cost_price,
                market_price: this.data.cargon_data.market_price,
                price: this.data.cargon_data.price,
                sku: this.data.cargon_data.sku,
                stock: this.data.cargon_data.stock,
                goods_sn: this.data.cargon_data.goods_sn,
                product_sn: this.data.cargon_data.product_sn
            })) : "supplier" == this.data.store && (d = {
                title: this.data.cargon_data.title,
                thumb: this.data.cargon_data.thumb,
                thumb_url: i,
                good_content: t,
                cost_price: this.data.cargon_data.cost_price,
                market_price: this.data.cargon_data.market_price,
                price: this.data.cargon_data.price,
                sku: this.data.cargon_data.sku,
                stock: this.data.cargon_data.stock,
                content_text: this.data.shopText
            }, this.data.isType || (d = {
                title: this.data.cargon_data.title,
                thumb: this.data.cargon_data.thumb,
                thumb_url: i,
                cost_price: this.data.cargon_data.cost_price,
                market_price: this.data.cargon_data.market_price,
                price: this.data.cargon_data.price,
                sku: this.data.cargon_data.sku,
                stock: this.data.cargon_data.stock
            }), this.data.selectedOptions3.length < 3 ? (d.category_pid = this.data.selectedOptions3[0], 
            d.category_cid = this.data.selectedOptions3[1]) : (d.category_pid = this.data.selectedOptions3[0], 
            d.category_cid = this.data.selectedOptions3[1], d.category_tid = this.data.selectedOptions3[2])), 
            this.triggerEvent("getChildoneData", d, {
                bubbles: !1
            });
        },
        jumpEvent: function() {
            for (var t in this.setData({
                jumpState: !0
            }), this.data.cargon_data) "" == this.data.cargon_data[t] && this.setData({
                jumpState: !1
            });
            0 == this.data.selectedOptions3.length && this.setData({
                jumpState: !1
            }), "" == this.data.imageUrl && this.setData({
                jumpState: !1
            });
        },
        getGoodsJson: function() {
            var t = this, e = "", i = {};
            "store" == t.data.store ? (e = a.getNetAddresss("plugin.store-cashier.frontend.store.goods.get-goods-detail"), 
            i = {
                goods_id: t.data.goods_id
            }) : "supplier" == t.data.store && (e = a.getNetAddresss("plugin.supplier.frontend.goods.goods-detail"), 
            i = {
                goods_id: t.data.goods_id
            }), a._postNetWork({
                url: e,
                showToastIn: !1,
                data: i,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        var i = t.data.selectedOptions3;
                        if (e.data.category_ids.parentid && i.push(Number(e.data.category_ids.parentid)), 
                        e.data.category_ids.childid && i.push(Number(e.data.category_ids.childid)), e.data.category_ids.thirdid && i.push(Number(e.data.category_ids.thirdid)), 
                        t.setData({
                            selectedOptions3: i
                        }), null != e.data.thumb_url && "" != e.data.thumb_url) {
                            for (var s = t.data.fileList3, d = 0; d < e.data.thumb_url.length; d++) s.push({
                                url: e.data.thumb_url[d]
                            });
                            console.log(t.data), console.log(s), t.setData({
                                fileList3: s,
                                infoArr: [],
                                upNumMax: e.data.thumb_url.length
                            });
                        }
                        t.setData({
                            "cargon_data.title": e.data.title,
                            "cargon_data.sku": e.data.sku,
                            imageUrl: e.data.thumb,
                            "cargon_data.thumb": e.data.thumb,
                            "cargon_data.price": e.data.price,
                            "cargon_data.market_price": e.data.market_price,
                            "cargon_data.cost_price": e.data.cost_price,
                            "cargon_data.stock": e.data.stock,
                            "cargon_data.thumb_url": e.data.thumb_url,
                            "cargon_data.goods_sn": e.data.goods_sn,
                            "cargon_data.product_sn": e.data.product_sn
                        }), t.commodityInit();
                    } else wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {}
            });
        },
        commodityInit: function() {
            for (var t = this.data.selectedOptions3, a = this.data.sectionOptions, e = [], i = [], s = "", d = 0; d < a.length; d++) if (a[d].id == t[0]) {
                this.setData({
                    "multiIndex[0]": d
                }), s += a[d].name;
                break;
            }
            if (console.log(this.data.multiIndex, "分类的数组"), console.log(a, "选中的项"), a[this.data.multiIndex[0]].children.length > 0) for (var n = 0; n < a[this.data.multiIndex[0]].children.length; n++) e.push({
                id: a[this.data.multiIndex[0]].children[n].id,
                name: a[this.data.multiIndex[0]].children[n].name
            });
            if (this.setData({
                "objectMultiArray[1]": e
            }), a[this.data.multiIndex[0]].children.length > 0) for (var r = 0; r < a[this.data.multiIndex[0]].children.length; r++) if (a[this.data.multiIndex[0]].children[r].id == t[1]) {
                this.setData({
                    "multiIndex[1]": r
                }), s += "/" + a[this.data.multiIndex[0]].children[r].name;
                break;
            }
            if (a[this.data.multiIndex[0]].children && a[this.data.multiIndex[0]].children.length > 0 && a[this.data.multiIndex[0]].children[this.data.multiIndex[1]].children && a[this.data.multiIndex[0]].children[this.data.multiIndex[1]].children.length > 0) for (var o = 0; o < a[this.data.multiIndex[0]].children[this.data.multiIndex[1]].children.length; o++) i.push({
                id: a[this.data.multiIndex[0]].children[this.data.multiIndex[1]].children[o].id,
                name: a[this.data.multiIndex[0]].children[this.data.multiIndex[1]].children[o].name
            });
            if (this.setData({
                "objectMultiArray[2]": i
            }), a[this.data.multiIndex[0]].children && a[this.data.multiIndex[0]].children.length > 0 && a[this.data.multiIndex[0]].children[this.data.multiIndex[1]].children && a[this.data.multiIndex[0]].children[this.data.multiIndex[1]].children.length > 0) for (var l = 0; l < a[this.data.multiIndex[0]].children[this.data.multiIndex[1]].children.length; l++) if (a[this.data.multiIndex[0]].children[this.data.multiIndex[1]].children[l].id == t[2]) {
                this.setData({
                    "multiIndex[2]": l
                }), s += "/" + a[this.data.multiIndex[0]].children[this.data.multiIndex[1]].children[l].name;
                break;
            }
            this.setData({
                regional: s
            });
        }
    }
});